﻿using Azure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SharedKernel.Infrastructure.Comm
{
    /// <summary>
    /// 统一返回基类
    /// </summary>
    public class ResponseInfo<TResInfo> 
    {
        /// <summary>
        /// 是否请求成功
        /// </summary>
        public bool IsSuccess { get; set; } 
        /// <summary>
        /// 提示信息
        /// </summary>
        public string? Message { get; set; }
        /// <summary>
        /// 返回数据
        /// </summary>
        public TResInfo? Data { get; set; }

        /// <summary>
        /// 初始化成功返回
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static ResponseInfo<TResInfo> Success(string msg = "请求成功", TResInfo? data = default)
        {
            return new ResponseInfo<TResInfo>
            {
                IsSuccess=true,
                Data=data,
                Message=msg
            };
        }
        /// <summary>
        /// 初始化失败返回
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static ResponseInfo<TResInfo> Fail(string msg = "请求失败", TResInfo? data = default)
        {
            return new ResponseInfo<TResInfo>
            {
                IsSuccess=false,
                Data=data,
                Message=msg
            };
        }
        /// <summary>
        /// 设置成功
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public ResponseInfo<TResInfo> SetSuccess(string msg = "请求成功", TResInfo? data = default)
        {
            IsSuccess=true;
            Message=msg;
            Data=data;
            return this;
        }
        /// <summary>
        /// 设置失败
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public ResponseInfo<TResInfo> SetFail(string msg = "请求失败", TResInfo? data = default)
        {
            IsSuccess=false;
            Message=msg;
            Data=data;
            return this;
        }
    }

}
